home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / hdf / unix / hdf3_2r2.lha / HDF3.2r2 / src / vrw.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-28  |  18.6 KB  |  669 lines

  1. /***************************************************************************
  2. *
  3. *
  4. *                         NCSA HDF version 3.2r2
  5. *                            October 30, 1992
  6. *
  7. * NCSA HDF Version 3.2 source code and documentation are in the public
  8. * domain.  Specifically, we give to the public domain all rights for future
  9. * licensing of the source code, all resale rights, and all publishing rights.
  10. *
  11. * We ask, but do not require, that the following message be included in all
  12. * derived works:
  13. *
  14. * Portions developed at the National Center for Supercomputing Applications at
  15. * the University of Illinois at Urbana-Champaign, in collaboration with the
  16. * Information Technology Institute of Singapore.
  17. *
  18. * THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED, FOR THE
  19. * SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT LIMITATION,
  20. * WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE
  21. *
  22. ****************************************************************************
  23. */
  24.  
  25. #ifdef RCSID
  26. static char RcsId[] = "@(#)$Revision: 1.2 $";
  27. #endif
  28. /*
  29. $Header: /hdf/hdf/v3.2r2/src/RCS/vrw.c,v 1.2 1992/10/23 00:14:11 koziol beta koziol $
  30.  
  31. $Log: vrw.c,v $
  32.  * Revision 1.2  1992/10/23  00:14:11  koziol
  33.  * Changed all DFIstr*() and DFImem*() calls to HDstr*() and HDmem*() calls
  34.  * #ifdef'd out the macros Jason defined for Hopen, Hclose, etc. for Vsets
  35.  * Replaced Vset VFREESPACE and VGETSPACE calls with actual calls to HDfreespace
  36.  * and HDgetspace
  37.  * Added a MS-Windows lower lower for file I/O (which may not be completely working
  38.  *
  39.  * Revision 1.1  1992/08/25  21:40:44  koziol
  40.  * Initial revision
  41.  *
  42. */
  43. /****************************************************************************e
  44. *
  45. * vrw.c
  46. * Part of the HDF VSet interface.
  47. *
  48. ************************************************************************/
  49.  
  50. #include "vg.h"
  51.  
  52. PRIVATE void Knumin
  53.     PROTO((BYTE *src,BYTE * dst,uint32 n,uint32 sdel,uint32 ddel));
  54.  
  55. PRIVATE void Knumout
  56.     PROTO((BYTE *src,BYTE * dst,uint32 n,uint32 sdel,uint32 ddel));
  57.  
  58. #ifdef PROTOTYPE
  59. PRIVATE void Knumin (BYTE *src, BYTE *dst, uint32 n, uint32 sdel, uint32 ddel)
  60. #else
  61. PRIVATE void Knumin (src, dst, n, sdel, ddel)
  62.     BYTE         *src, *dst;
  63.     uint32      n, sdel, ddel;
  64. #endif
  65.  
  66. {
  67.   if (vjv) {
  68.     sprintf(sjs, "  -->> Knumin: n=%ld sdel=%ld ddel=%ld src=%lx dst=%lx\n",
  69.             n, sdel, ddel, src, dst); zj;
  70.   }
  71.   
  72.   (*DFKnumin) (src, dst, n, sdel, ddel);
  73.   
  74. }
  75.  
  76. #ifdef PROTOTYPE
  77. PRIVATE void Knumout (BYTE *src, BYTE *dst, uint32 n, uint32 sdel, uint32 ddel)
  78. #else
  79. PRIVATE void Knumout (src, dst, n, sdel, ddel)
  80.     BYTE         *src, *dst;
  81.     uint32      n, sdel, ddel;
  82. #endif
  83.  
  84. {
  85.   if (vjv) {
  86.     sprintf(sjs, "  -->> Knumout: n=%ld sdel=%ld ddel=%ld src=%ld dst=%ld\n",
  87.             n, sdel, ddel, src, dst); zj;
  88.   }
  89.   
  90.   (*DFKnumout) (src, dst, n, sdel, ddel);
  91.  
  92. }
  93.  
  94. /* --------------------------- VSseek -------------------------------------- */
  95.  
  96. /* 
  97.     VSseek  - now allows seeks for reads AND writes. 30/mar/92 jason ng
  98.  
  99.     Seeks to an element boundary within a vdata
  100.     Vdata must be attached with "r" or "w" access.
  101.     Specify eltpos = 0 for 1st element, 1 for 2nd element etc.
  102.     RETURNS -1 on error
  103.     RETURNS position of element seeked to (0 or a +ve integer)
  104.         (eg  returns 5 if seek to the 6th element, etc)
  105. */
  106.  
  107. #ifdef PROTOTYPE
  108. PUBLIC int32 VSseek (VDATA *vs, int32 eltpos)    
  109. #else
  110.  
  111.  
  112. PUBLIC int32 VSseek (vs, eltpos)    
  113.     VDATA *    vs;
  114.     int32       eltpos;
  115.  
  116. #endif
  117.  
  118. {
  119.     int32     stat, offset;
  120.     char *     FUNC = "VSseek";
  121.  
  122.     if ((vs==NULL) || (eltpos < 0)) {HERROR(DFE_ARGS); return(FAIL);}
  123.  
  124.     offset  = eltpos * vs->wlist.ivsize;
  125.  
  126.     stat = QQseek (vs->aid, offset, DF_START);
  127.     if (stat==FAIL) {
  128.           HERROR(DFE_BADSEEK);
  129.           return(FAIL);
  130.         }
  131.  
  132.     return(eltpos); 
  133.  
  134. } /* Vseek */
  135.  
  136. /* ------------------------------------------------------------------------ */
  137.  
  138. /*
  139.     VSread
  140.     Reads a specified number of elements' worth of data from a vdata.
  141.     Data will be returned to you interlaced in the way you specified.
  142.     RETURNS -1 if error
  143.     RETURNS the number of elements read (0 or a +ve integer).
  144. */
  145.  
  146. PRIVATE int32 Vtbufsize = 0;
  147. PRIVATE BYTE *Vtbuf = NULL;
  148.  
  149. #ifdef PROTOTYPE
  150. PUBLIC int32 VSread (VDATA *vs,BYTE buf[], int32 nelt, int32 interlace)  
  151. #else
  152. PUBLIC int32 VSread (vs, buf, nelt, interlace)  
  153.     VDATA   *vs;
  154.     int32    nelt;
  155.     int32    interlace;
  156.     BYTE    buf[];
  157. #endif
  158.  
  159. {
  160.     register int16 isize,esize,hsize;
  161.     register BYTE    *b1,*b2;
  162.     int32             i,j, nv, offset, type;
  163.     VWRITELIST         *w;
  164.     VREADLIST          *r;
  165. /*
  166.     register BYTE    *tbuf;
  167. */
  168.     int32             uvsize; /* size of "element" as NEEDED by user */
  169.     int32            stat;
  170.     char *     FUNC = "VSread";
  171.  
  172.     if(vs == NULL)        { HERROR(DFE_ARGS); return(FAIL); }
  173. /* Allow people to read when they have write access 
  174.     if(vs->access != 'r')    { HERROR(DFE_BADACC); return(FAIL); }
  175. */
  176.     if(vs->nvertices == 0)    { HERROR(DFE_ARGS); return(FAIL); }
  177.  
  178.     if(vexistvs(vs->f,vs->oref) == FAIL) { HERROR(DFE_NOVS); return(FAIL); }
  179.  
  180.     if(interlace != FULL_INTERLACE  && interlace != NO_INTERLACE)
  181.           { HERROR(DFE_ARGS); return(FAIL); }
  182.  
  183.     w = &(vs->wlist);
  184.     r = &(vs->rlist);
  185.     hsize = vs->wlist.ivsize;         /* size as stored in HDF */
  186.  
  187.     /* alloc space (Vtbuf) for reading in the raw data from vdata */
  188.         if(Vtbufsize < nelt * hsize) {
  189.           Vtbufsize = nelt * hsize;
  190.           if(Vtbuf) HDfreespace(Vtbuf);
  191.           if((Vtbuf = (BYTE *) HDgetspace ( Vtbufsize )) == NULL) {
  192.             HERROR(DFE_NOSPACE);
  193.             return(FAIL);
  194.           }
  195.         }
  196.  
  197.     /* ================ start reading ============================== */
  198.     /* ================ start reading ============================== */
  199.  
  200.     QQQuerylength(vs->aid, &stat);
  201.     nv = QQread (vs->aid, nelt * hsize, (uint8*) Vtbuf);
  202.  
  203.     if ( nv != nelt*hsize ) {
  204.           HERROR(DFE_READERROR);
  205.           HEreport("Tried to read %d, only read %d", nelt * hsize, nv);
  206.           return FAIL;
  207.         }
  208.  
  209.     /* ================ done reading =============================== */
  210.     /* ================ done reading =============================== */
  211.  
  212.  
  213.     /* 
  214.         Now, convert and repack field(s) from Vtbuf into buf.    
  215.  
  216.         This section of the code deals with interlacing. In all cases
  217.         the items for each of the fields are converted and shuffled 
  218.         around from the internal buffer "Vtbuf" to the user's buffer 
  219.         "buf".  
  220.  
  221.         There are 5 cases :
  222.         (A) user=NO_INTERLACE   & vdata=FULL_INTERLACE) 
  223.           (B) user=NO_INTERLACE   & vdata=NO_INTERLACE) 
  224.           (C) user=FULL_INTERLACE & vdata=FULL_INTERLACE) 
  225.         (D) user=FULL_INTERLACE & vadat=NO_INTERLACE) 
  226.         (E) SPECIAL CASE when field has order>1. 
  227.  
  228.         Cases (A)-(D) handles multiple fields of order 1.
  229.         Case (E) handles one field of order>1. Interlace is
  230.         irrelevant in this case. The case where there are 
  231.         multiple fields of order>1 is prevented from
  232.         existing by VSsetfields explicitly checking for this.
  233.                 
  234.     */
  235.  
  236.     /* ----------------------------------------------------------------- */
  237.     /* CASE  (E): Special Case For one field with order >1 only */
  238.  
  239.     if (w->n == 1 && w->order[0] > 1) {
  240.         b1 = buf;
  241.         b2 = Vtbuf;
  242.         esize = w->esize[0];
  243.         isize = w->isize[0];
  244.         type = w->type[0];
  245.  
  246.         if (vjv) {
  247.                   sprintf(sjs,">> R  SPECIAL (E) order=%d esiz=%d isiz=%d nelt=%ld vsize %d\n",
  248.                           w->order[0], esize, isize, nelt , hsize); zj;
  249.                   sprintf(sjs,"@VSREAD: type is %ld\n", type); zj;
  250.         }
  251.  
  252.         /* Errr WORKS */
  253.         DFKsetNT(type); 
  254.         Knumin (b2, b1, (uint32) w->order[0] * nelt, 
  255.                         (uint32) isize/w->order[0],
  256.                         (uint32) esize/w->order[0]);
  257.     } /* case (e) */
  258.  
  259.     /* ----------------------------------------------------------------- */
  260.     /* CASE  (A):  user=none, vdata=full */
  261.  
  262.     else if (interlace==NO_INTERLACE && vs->interlace==FULL_INTERLACE) {
  263.         if (vjv) { sprintf(sjs,">> R  CASE  (A): iu=none, iv=full \n"); zj;}
  264.  
  265.         b1 = buf;
  266.         for (j=0;j<r->n;j++) {
  267.             i     = r->item[j];
  268.             b2    = Vtbuf + w->off[i];
  269.             type  = w->type[i];
  270.             isize = w->isize[i];        /* QAK */
  271.             esize = w->esize[i];
  272.  
  273.             /* Arrr ? */
  274.             DFKsetNT(type); 
  275.             Knumin (b2, b1, (uint32) w->order[0] * nelt, 
  276.                                 (uint32) isize/w->order[0],
  277.                                 (uint32) esize/w->order[0]);
  278.             b1 += (nelt * esize);
  279.         }
  280.     } /* case (a) */
  281.  
  282.     /* ----------------------------------------------------------------- */
  283.     /* CASE  (B):  user=none, vdata=none */
  284.     else if (interlace==NO_INTERLACE && vs->interlace==NO_INTERLACE) {
  285.         if (vjv) { sprintf(sjs,">> R  CASE  (B):  iu=none, iv=none\n"); zj; }
  286.  
  287.         b1 = buf;
  288.         for (j=0;j<r->n;j++) {
  289.             i     = r->item[j];
  290.             b2    = Vtbuf + w->off[i] * nelt;
  291.             type  = w->type[i];
  292.             esize = w->esize[i];
  293.             isize = w->isize[i];
  294.  
  295.             /* Brrr ? */
  296.             DFKsetNT(type); 
  297.             Knumin (b2, b1, (uint32) nelt, (uint32) isize, (uint32) esize);
  298.             b1 += (nelt * esize);
  299.         }
  300.     } /* case (b) */
  301.  
  302.     /* ----------------------------------------------------------------- */
  303.     /* CASE  (C):  iu=full, iv=full */
  304.     else if (interlace==FULL_INTERLACE && vs->interlace==FULL_INTERLACE) {
  305.         if (vjv) { sprintf(sjs,">> R  CASE  (C):  iu=full, iv=full\n"); zj; }
  306.  
  307.         for (uvsize=0, j=0;j<r->n;j++)
  308.             uvsize += w->esize[r->item[j]];
  309.  
  310.         for (offset=0,j=0;j<r->n;j++) {
  311.             i     = r->item[j];
  312.             b1    = buf + offset;
  313.             b2    = Vtbuf + w->off[i];
  314.             type  = w->type[r->item[j]];
  315.             esize = w->esize[i];
  316.             /* isize = w->isize[i]; QAK */
  317.  
  318.             /* Crrr WORKS  */
  319.             DFKsetNT(type); 
  320.             Knumin (b2, b1, (uint32) nelt, (uint32) hsize, (uint32) uvsize);
  321.             offset += esize;
  322.         }
  323.     } /* case (c) */
  324.  
  325.  
  326.     /* ----------------------------------------------------------------- */
  327.     /* CASE  (D):  user=full, vdata=none */
  328.     else if(interlace==FULL_INTERLACE && vs->interlace==NO_INTERLACE) {
  329.  
  330.         if (vjv) { sprintf(sjs,">> R  CASE  (D):  iu=full, iv=none\n"); zj; }
  331.  
  332.         for (uvsize=0, j=0;j<r->n;j++)
  333.             uvsize += w->esize[r->item[j]];
  334.  
  335.         for (offset=0,j=0;j<r->n;j++) {
  336.             i     = r->item[j];
  337.             b1    = buf + offset;
  338.             b2    = Vtbuf + w->off[i] * nelt;
  339.             type  = w->type[i];
  340.             isize = w->isize[i];
  341.  
  342.             /* Drrr ? */
  343.             DFKsetNT(type); 
  344.             Knumin (b2, b1, (uint32) nelt, 
  345.                                 (uint32) isize, 
  346.                                 (uint32) uvsize);
  347.             offset +=isize;
  348.         }
  349.     } /* case (d) */
  350. /*
  351.     HDfreespace (tbuf);
  352. */
  353.     return(nv/hsize);
  354.  
  355. } /* VSread */
  356.  
  357.  
  358. /* ------------------------------------------------------------------ */
  359. /* debugging routine */
  360.  
  361. #ifdef PROTOTYPE
  362. void bytedump (char *ss, BYTE buf[], int32 n)
  363. #else
  364.  
  365. void bytedump (ss, buf, n)
  366.     char         *ss;
  367.     BYTE        buf[]; 
  368.     int32     n; 
  369.  
  370. #endif
  371.  
  372. {
  373.   int32 i;
  374.   printf("BYTEDUMP at %ld [%s %ld]: ",buf, ss, n);
  375.   for(i=0;i<n;i++) printf(" %x", buf[i]);
  376.   printf("\n");
  377.   fflush(stdout);
  378. }
  379.  
  380. /* ------------------------------------------------------------------ */
  381. /*
  382.     VSwrite
  383.     Writes a specified number of elements' worth of data to a vdata.
  384.     You must specify how your data in your buffer is interlaced.
  385.     
  386.     RETURNS -1 if error
  387.     RETURNS the number of elements written (0 or a +ve integer).
  388.  
  389.     NEW
  390.     create an aid, and write out if this is the first time.
  391.     (otherwise) subsequent writes result in link-blocks.
  392.  
  393. */
  394.  
  395. #ifdef PROTOTYPE
  396. PUBLIC int32 VSwrite (VDATA *vs, BYTE buf[], int32 nelt, int32 interlace)
  397. #else
  398. PUBLIC int32 VSwrite (vs, buf, nelt, interlace)
  399.  
  400.     VDATA     *vs;
  401.     int32        nelt;
  402.     int32        interlace;
  403.     BYTE        buf[];
  404.  
  405. #endif
  406.  
  407. {
  408.     register int16    isize,esize,hsize;
  409.     register BYTE     *b1,*b2;
  410. /*
  411.     register BYTE    *tbuf;
  412. */
  413.     int32         j,type, offset;
  414.     int32         special;
  415.         int32           position, new_size;
  416.     VWRITELIST    *w;
  417.     int32         uvsize;        /* size of "element" as needed by user */
  418.     char *     FUNC = "VSwrite";
  419.  
  420.     if ((nelt <= 0) || (vs == NULL))       { HERROR(DFE_ARGS); return(FAIL); }
  421.     if (vs->access != 'w')                    { HERROR(DFE_BADACC); return(FAIL); }
  422.         if ( -1L == vexistvs(vs->f,vs->oref) ) { HERROR(DFE_NOVS); return(FAIL); }
  423.     if (vs->wlist.ivsize == 0)     { HERROR(DFE_NOVS);
  424.                                            HEreport("w: vsize 0. fields not set for write!");
  425.                                            return(FAIL); }
  426.  
  427.     if (interlace != NO_INTERLACE && interlace != FULL_INTERLACE )
  428.           { HERROR(DFE_ARGS); return(FAIL); }
  429.  
  430.     w = (VWRITELIST*) &vs->wlist;
  431.     hsize = w->ivsize;         /* as stored in HDF file */
  432.  
  433.     /* alloc space (Vtbuf) for writing out the data */
  434.         if(Vtbufsize < nelt * hsize) {
  435.           Vtbufsize = nelt * hsize;
  436.           if(Vtbuf) HDfreespace(Vtbuf);
  437.           if((Vtbuf = (BYTE *) HDgetspace ( Vtbufsize )) == NULL) {
  438.             HERROR(DFE_NOSPACE);
  439.             return(FAIL);
  440.           }
  441.         }
  442.  
  443. /*
  444.     if((tbuf = (BYTE *) HDgetspace ( nelt * hsize)) == NULL) {
  445.           HERROR(DFE_NOSPACE);
  446.           return(FAIL);
  447.         }
  448. */
  449.  
  450.     /* 
  451.         First, convert and repack field(s) from Vtbuf into buf.    
  452.  
  453.         This section of the code deals with interlacing. In all cases
  454.         the items for each of the fields are converted and shuffled 
  455.         around from the user's buffer "buf" to the internal's buffer 
  456.         "Vtbuf".  The data in "Vtbuf" is then written out to the vdata.
  457.  
  458.         There are 5 cases :
  459.         (A) user=NO_INTERLACE   & vdata=FULL_INTERLACE) 
  460.       (B) user=NO_INTERLACE   & vdata=NO_INTERLACE) 
  461.       (C) user=FULL_INTERLACE & vdata=FULL_INTERLACE) 
  462.       (D) user=FULL_INTERLACE & vadat=NO_INTERLACE) 
  463.         (E) SPECIAL CASE when field has order>1. 
  464.  
  465.         Cases (A)-(D) handles multiple fields of order 1.
  466.         Case (E) handles one field of order>1. Interlace is
  467.         irrelevant in this case. The case where there are 
  468.         multiple fields of order>1 is prevented from
  469.         existing by VSsetfields explicitly checking for this.
  470.  
  471.     --------------------------------------------------------------------- */
  472.     /* CASE  (E): Special Case For one field with order >1 only */
  473.  
  474.     if (w->n == 1 && w->order[0] > 1) {
  475.         b1    = buf;
  476.         b2    = Vtbuf;
  477.         esize = w->esize[0];
  478.         isize = w->isize[0];
  479.         type  = w->type[0];
  480.  
  481.         if (vjv) {
  482.             sprintf(sjs,">> W SPECIAL(E) order=%d esiz=%d isiz=%d nelt=%ld vsiz=%d\n",
  483.                         w->order[0], esize, isize, nelt, hsize); zj;
  484.             sprintf(sjs,"@VSWRITE: type = %ld\n", type); zj;
  485.         }
  486.  
  487.     /* Ewww WORKS */
  488.         DFKsetNT(type); 
  489.           Knumout(b1, b2, (uint32) w->order[0] * nelt, 
  490.                           (uint32) esize/w->order[0],
  491.                           (uint32) isize/w->order[0]);
  492.     } /* case (e) */
  493.  
  494.  
  495.     /* ----------------------------------------------------------------- */
  496.     /* CASE  (A):  user=none, vdata=full */
  497.     else if (interlace==NO_INTERLACE && vs->interlace==FULL_INTERLACE) {
  498.  
  499.         if (vjv) {sprintf(sjs, ">> W  CASE  (A):  iu=none, iv=full \n"); zj;} 
  500.  
  501.         b1 = buf;
  502.         for (j=0;j<w->n;j++) {
  503.             b2    = Vtbuf + w->off[j];
  504.             type  = w->type[j];
  505.             esize = w->esize[j];
  506.  
  507.             /* Awww ? */
  508.             DFKsetNT(type); 
  509.             Knumout (b1, b2, (uint32) nelt, 
  510.                                  (uint32) esize,
  511.                                  (uint32) hsize);
  512.             b1 += (nelt * esize);
  513.         }
  514.  
  515.     } /* case (a) */
  516.  
  517.     /* --------------------------------------------------------------------- */
  518.     /* CASE  (B):  user=none, vdata=none */
  519.     else if (interlace==NO_INTERLACE && vs->interlace==NO_INTERLACE) {
  520.  
  521.         if (vjv) { sprintf(sjs,">> W  CASE  (B):  iu=none, iv=none\n"); zj; }
  522.  
  523.         b1 = buf;
  524.         for (j=0;j<w->n;j++) {
  525.             b2    = Vtbuf + w->off[j] * nelt;
  526.             type  = w->type[j];
  527.             esize = w->esize[j];
  528.             isize = w->isize[j];
  529.  
  530.             /* Bwww ? works sometimes */
  531.             DFKsetNT(type); 
  532.             Knumout (b1, b2, (uint32) nelt, 
  533.                                  (uint32) esize, 
  534.                                  (uint32) isize);
  535.             b1 += (nelt * esize);
  536.         }
  537.  
  538.     } /* case (b) */
  539.  
  540.     /* ----------------------------------------------------------------- */
  541.     /* CASE  (C):  user=full, vdata=full */
  542.     else if (interlace==FULL_INTERLACE && vs->interlace==FULL_INTERLACE) {
  543.         if (vjv) { sprintf(sjs, ">> W  CASE  (C):  iu=full, iv=full\n"); zj;}
  544.  
  545.         for (uvsize=0, j=0;j<w->n;j++)
  546.             uvsize += w->esize[j];
  547.  
  548.         for (offset=0,j=0;j<w->n;j++) {
  549.             b1    = buf + offset;
  550.             b2    = Vtbuf + w->off[j];
  551.             type  = w->type[j];
  552.             esize = w->esize[j];
  553.             isize = w->isize[j];
  554.  
  555.             /* Cwww WORKS  */
  556.             DFKsetNT(type); 
  557.             Knumout (b1, b2, (uint32) nelt, 
  558.                                  (uint32) uvsize, 
  559.                                  (uint32) hsize);
  560.             offset += esize;
  561.         }
  562.  
  563.     } /* case (c) */
  564.  
  565.     /* ----------------------------------------------------------------- */
  566.     /* CASE  (D):  user=full, vdata=none */
  567.     else if (interlace==FULL_INTERLACE && vs->interlace==NO_INTERLACE) {
  568.  
  569.         if (vjv) { sprintf(sjs, ">> W  CASE  (D):  iu=full, iv=none\n"); zj;}
  570.  
  571.         for (uvsize=0, j=0;j<w->n;j++)
  572.             uvsize += w->esize[j];
  573.  
  574.         for (offset=0,j=0;j<w->n;j++) {
  575.             b1    = buf  + offset;
  576.             b2    = Vtbuf + w->off[j] * nelt;
  577.             type  = w->type[j];
  578.             isize = w->isize[j];
  579.             esize = w->esize[j];
  580.  
  581.             /* Dwww ? */
  582.             DFKsetNT(type); 
  583.             Knumout (b1, b2, (uint32) nelt, 
  584.                                  (uint32) uvsize, 
  585.                                  (uint32) isize);
  586.             offset +=esize;
  587.         }
  588.     } /* case (d) */
  589.  
  590.  
  591.     /* ================ start writing ============================== */
  592.     /* ================ start writing ============================== */
  593.  
  594. #if 1
  595.     if (vs->aid == 0) { /* aid not allocated yet */
  596.           vs->aid = QQstartwrite (vs->f, VSDATATAG, vs->oref, 
  597.                                   (int32) nelt * hsize);
  598.           if (vs->aid == FAIL) { HERROR(DFE_BADAID); return(FAIL); }
  599.     }
  600.  
  601.     /* 
  602.          * promote to link-block if vdata exists and is not already one 
  603.          *  AND we are incresing its size
  604.          */
  605.         HQueryposition(vs->aid, &position);
  606.         new_size = (position / vs->wlist.ivsize) + nelt;
  607.  
  608.     if (vs->nvertices > 0) {
  609.           QQQueryspecial(vs->aid, &special);
  610.           if (!special && (new_size > vs->nvertices)) { 
  611.             QQendaccess(vs->aid);
  612.             vs->aid = HLcreate(vs->f, VSDATATAG , vs->oref, 
  613.                                VDEFAULTBLKSIZE, VDEFAULTNBLKS);
  614.             /* seek back to correct point */
  615.             j = QQseek(vs->aid, position, DF_START); 
  616.             if(vjv) {sprintf(sjs,"promotion to LINK-BLOCK seek stat is %ld\n",j); zj;}
  617.           }
  618.         }
  619.       
  620.     j = QQwrite (vs->aid,  nelt * hsize, (uint8*) Vtbuf);
  621.     if (j != nelt * hsize) { 
  622.           sprintf(sjs,"QQwrite of %ld : %ld bytes written\n", nelt * hsize,j); zj;
  623.         }
  624.  
  625. /*
  626.     HDfreespace (tbuf);
  627. */
  628.  
  629.         if(new_size > vs->nvertices) vs->nvertices = new_size;
  630.  
  631.     vs->marked = 1;
  632.     return (nelt);
  633. #endif
  634.  
  635. #if 0
  636.     {{ /* THIS VERSION WITH VMBLOCKS */
  637.         VMBLOCK * vm, *t;
  638.         int32 vmsize;
  639.         vmsize = nelt * hsize;
  640.         /* sprintf(sjs, "VMBLOCK saved: size=%ld\n", vmsize); zj; */
  641.  
  642.         vm  = (VMBLOCK*) HDgetspace(sizeof(VMBLOCK));
  643.         if (vm==NULL) { 
  644.             sprintf(sjs,"VSwrite: alloc vmblock err\n"); zj; 
  645.             return(0);
  646.             }
  647.         vm->mem     = tbuf;
  648.         vm->n     = vmsize;
  649.         vm->next = NULL;
  650.  
  651.         t = vs->vm;
  652.         if (t == NULL) { vs->vm = vm; }
  653.         else {
  654.             t = vs->vm;
  655.             while (t->next != NULL)  t= t->next;
  656.             t->next = vm;
  657.             }        
  658.  
  659.         vs->nvertices += nelt;
  660.         vs->marked = 1;
  661.         return (nelt);
  662.         /* END OF VMBLOCK VERSION */ }}
  663. #endif
  664.  
  665.  
  666. } /* VSwrite */
  667.  
  668. /* ------------------------------------------------------------------ */
  669.